let cachedStockData = [];
let weekPriceCache = {}; // 周价格信息
let conceptHistoryCache = [];
let lowPriceCache = require('../config/lowPriceMap'); // 最低买入价信息
let highPriceCache = require('../config/highPriceMap'); // 最高卖出价信息
let sectorCache = require('../config/sectorMapCode'); // 板块信息
let regionCache = require('../config/regionMapCode'); // 区域信息
let conceptCache = require('../config/conceptMapCode'); // 概念信息
let roeCache = require('../config/roeMapCode'); // 净资产收益率信息
let ratioCache = require('../config/ratioMapCode'); // 资产负债率信息

module.exports = {
    getCache: () => cachedStockData,
    updateCache: (newData) => {
        cachedStockData = newData;
    },
    getStockByCode: (code) => {
        return cachedStockData.find((item) => item.code === code);
    },
    getStocksByCode: (codes) => {
        return codes.map((code) => {
            return cachedStockData.find((item) => item.code === code);
        });
    },
    // 周价格缓存
    getWeekPriceCache: () => weekPriceCache,
    updateWeekPriceCache: (newData) => {
        weekPriceCache = newData;
    },
    // 近百日最低买入价格缓存
    getLowPriceCache: () => lowPriceCache,
    updateLowPriceCache: (newData) => {
        lowPriceCache = newData;
    },
    updateLowPriceCacheByCode: (code, newData) => {
        lowPriceCache[code] = newData;
    },
    // 近百日最高卖出价格缓存
    getHighPriceCache: () => highPriceCache,
    updateHighPriceCache: (newData) => {
        highPriceCache = newData;
    },
    updateHighPriceCacheByCode: (code, newData) => {
        highPriceCache[code] = newData;
    },
    // 板块信息缓存
    getSectorCache: () => sectorCache,
    updateSectorCache: (newData) => {
        sectorCache = newData;
    },
    getSectorList: () => {
        let allSectorList = cachedStockData.map((item) => item.sector);
        return [...new Set(allSectorList)];
    },
    // 地区信息缓存
    getRegionCache: () => regionCache,
    updateRegionCache: (newData) => {
        regionCache = newData;
    },
    // 概念信息缓存
    getConceptCache: () => conceptCache,
    updateConceptCache: (newData) => {
        conceptCache = newData;
    },
    getConceptList: () => {
        let allConceptList = cachedStockData.map((item) => item.concept).map((item) => item.split(',')).flat();
        return [...new Set(allConceptList)];
    },
    // 净资产收益率信息缓存
    getRoeCache: () => roeCache,
    updateRoeCache: (newData) => {
        roeCache = newData;
    },
    // 资产负债率信息缓存
    getRatioCache: () => ratioCache,
    updateRatioCache: (newData) => {
        ratioCache = newData;
    },
    // 历史概念信息缓存
    getConceptHistoryCache: () => conceptHistoryCache,
    updateConceptHistoryCache: () => {
        let allConceptList = cachedStockData.map((item) => item.concept).map((item) => item.split(',')).flat();
        conceptHistoryCache = [...new Set(allConceptList)];
    },
};
